<template>
  <div>
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :isSelectColumn="false"
      :params="fetchParams"
      :datakey="'rows'"
      columnsRef="ltInsurance"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls" slot-scope="props">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-plus"
          @click="
            visible = true;
            type = 'add';
          "
          >新增</el-button
        >
        <!-- <el-button size="small">导出</el-button> -->
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visible"
      :title="type == 'add' ? '新增' : type == 'edit' ? '修改' : '明细'"
      :width="'900px'"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 50px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <addInsuranceCompany :type="type" :insurationCode="insurationCode" :changeHandle="changeHandle" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { dictionary } from '@/utils/dictMixin';
import addInsuranceCompany from './addInsuranceCompany';
import { getInsuranceCompany } from '@/api/repair/repairBusiness/insuranceCompany';

export default {
  name: 'InsuranceCompany',
  components: {
    addInsuranceCompany
  },
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      // topFilterList: this.createTopFilterList(),
      visible: false,
      fetchApi: getInsuranceCompany,
      fetchParams: { xhrAbort: false },
      columns: this.createTableColumns(),
      insurationCode: '',
      type: ''
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.isEdit(props.row)}>
                  编辑
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={() => this.detail(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '保险公司代码',
          dataIndex: 'INSURATION_CODE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '保险公司名称',
          dataIndex: 'INSURATION_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '保险公司简称',
          dataIndex: 'INSURATION_SHORT_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人',
          dataIndex: 'CONTACTOR_NAME',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人电话',
          dataIndex: 'CONTACTOR_PHONE',
          width: 130,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人手机',
          dataIndex: 'CONTACTOR_MOBILE',
          width: 130,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '传真',
          dataIndex: 'FAX',
          width: 130,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '地址',
          dataIndex: 'ADDRESS',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '邮编',
          dataIndex: 'ZIP_CODE',
          width: 110,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开户银行',
          dataIndex: 'BANK',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开户账号',
          dataIndex: 'BANK_ACCOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '机构级别',
          dataIndex: 'INSURATION_LEVEL',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '机构级别',
          dataIndex: 'INSURATION_HIGHER',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '保险中介机构',
          dataIndex: 'INSURATION_MEDIUM',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '其他商业险返利点',
          dataIndex: 'BUSI_INSURANCE_REBATE_NUM',
          width: 175,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '其他交强险返利点',
          dataIndex: 'COM_INSURANCE_REBATE_NUM',
          width: 175,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '传统商业返利点',
          dataIndex: 'BUSI_INSURANCE_REBATE_NUMC',
          width: 175,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '传统交强险返利点',
          dataIndex: 'COM_INSURANCE_REBATE_NUMC',
          width: 175,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '信贷商业险返利点',
          dataIndex: 'BUSI_INSURANCE_REBATE_NUMX',
          width: 175,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '信贷交强险返利点',
          dataIndex: 'COM_INSURANCE_REBATE_NUMX',
          width: 175,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电话营销商业险返利点',
          dataIndex: 'BUSI_INSURANCE_REBATE_NUMD',
          width: 185,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电话营销交强险返利点',
          dataIndex: 'COM_INSURANCE_REBATE_NUMD',
          width: 185,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否启用',
          dataIndex: 'IS_APPLY',
          width: 120,
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.IS_APPLY, 1004)}</span>;
          }
        },
        {
          title: '数据来源',
          dataIndex: 'OEM_TAG',
          width: 120,
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.OEM_TAG, 1045)}</span>;
          }
        }
      ];
    },
    isEdit(row) {
      this.visible = true;
      this.type = 'edit';
      this.insurationCode = row.INSURATION_CODE + '';
    },
    detail(row) {
      this.visible = true;
      this.type = 'show';
      this.insurationCode = row.INSURATION_CODE + '';
    },
    closeHandler(val) {
      this.visible = val;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    }
  }
};
</script>

<style lang="less" scoped></style>
